//
//  LFReminderTool.m
//  AntMarket
//
//  Created by LF on 2017/3/30.
//  Copyright © 2017年 LF. All rights reserved.
//

#import "LFReminderTool.h"

@implementation LFReminderTool

+ (void)showWithStatus:(NSString *)status
{
    [super showWithStatus:status];
}

+ (void) lf_makeTostInView:(UIView *)view position:(ToastPosition)position text:(NSString *)text duration:(CGFloat)duration
{
    [self toastInView:view position:position text:text duration:duration];
}

+ (void) lf_makeTostInView:(UIView *)view text:(NSString *)text
{
    [self toastInView:view position:ToastPositionCenter text:text duration:2.0f];
}

+ (void) toastInView:(UIView *)view position:(ToastPosition)position text:(NSString *)text duration:(CGFloat)duration
{
    id PositionString;
    switch (position) {
        case ToastPositionTop:
            PositionString = CSToastPositionTop;
            break;
        case ToastPositionCenter:
            PositionString = CSToastPositionCenter;
            break;
        case ToastPositionBottom:
            PositionString = CSToastPositionBottom;
            break;
            
        default:
            break;
    }
    [view makeToast:text duration:duration position:PositionString];
}

#pragma mark - Block
+ (void)load{
    [LFReminderTool setDefaultStyle:SVProgressHUDStyleDark];
    [LFReminderTool setMinimumDismissTimeInterval:1.5f];
//    [LFReminderTool setBackgroundColor:RGBColor(0, 0, 0, 0.8)];
//    [LFReminderTool setForegroundColor:[UIColor whiteColor]];
//    [LFReminderTool setDefaultMaskType:SVProgressHUDMaskTypeGradient];
    [LFReminderTool setInfoImage:nil];
}

void ShowHUD(void) {
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool show];
        });
    } else {
        [LFReminderTool show];
    }
}

void ShowSuccessStatus(NSString *statues){
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool showSuccessWithStatus:statues];
        });
    }else{
        [LFReminderTool showSuccessWithStatus:statues];
    }
}


void ShowMessage(NSString *statues){
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool showInfoWithStatus:statues];
        });
    }else{
        [LFReminderTool showInfoWithStatus:statues];
    }
}

void ShowErrorStatus(NSError *error){
    NSString *statues;
    if (error.code == CUSTOM_ERROR_CODE) {
        statues = error.localizedDescription;
    } else {
        if (error.code == -1001) {
            statues = @"连接超时";
        } else {
            statues = NetError;
        }
    }
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool showErrorWithStatus:statues];
//            [LFReminderTool showProgress:0.5 status:@"上传"];
        });
    }else{
        [LFReminderTool showErrorWithStatus:statues];
    }
}

void ShowMaskStatus(NSString *statues){
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool showWithStatus:statues];
        });
    }else{
        [LFReminderTool showWithStatus:statues];
    }
}

void ShowProgress(CGFloat progress){
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool showProgress:progress];
        });
    }else{
        [LFReminderTool showProgress:progress];
    }
}

void DismissHud(void){
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [LFReminderTool dismiss];
        });
    }else{
        [LFReminderTool dismiss];
    }
}

@end
